# -*- coding: utf-8 -*-
# マスタデータ登録
# rake db:setup にて登録実行可能
begin
  ActiveRecord::Base.transaction do
    # デフォルトロール登録
    puts "Role creating..."
    Role.delete_all
    Role.create(:name => "admin")              # システム管理者
    Role.create(:name => "community_master")   # コミュニティマスタ
    Role.create(:name => "community_user")     # コミュニティユーザー

    # 管理者ユーザー登録
    puts "Admin user creating..."
    quentin = User.create(:login => "quentin",
                          :nick_name => "administrator",
                          :password => "monkey",
                          :password_confirmation => "monkey")

    puts "Admin user settings creating..."
    setting = Setting.new(:message_format_type => "plain",
                          :blog_format_type => "markdown")
    setting.user = quentin
    setting.save

    puts "Admin user profile creating..."
    profile = Profile.new(:permissions => "none")
    profile.user = quentin
    profile.save

    # quentinを管理者登録
    puts "Add admin role for quentin..."
    quentin.roles << Role.admin

    puts "---------"
    puts "complete."
  end
rescue => ex
  puts "error occured."
  p ex
end
